package A05_栈;

import java.util.Scanner;

/**
 * @Author: KingWang
 * @Date: 2021/6/1
 * @Desc:
 **/
public class StackDemo {

    public static void main(String[] args) {
        Stack<Integer> stack = new Stack(3);

        Scanner scanner = new Scanner(System.in);
        boolean quit = false;
        while(!quit){

            System.out.println("请选择：1-push,2-pop,3-show,0-quit");
            String str = scanner.next();
            try{
                int num = Integer.valueOf(str);

                switch (num){
                    case 1:
                        System.out.println("请输入入栈的数字：");
                        String input = scanner.next();
                        stack.push(Integer.valueOf(input));
                        break;
                    case 2:stack.pop();break;
                    case 3: stack.show();break;
                    case 0: quit = true; break;
                    default:
                        System.out.println("输入选项不正确，请重新选择：");
                }

            }catch (Exception e){
                e.printStackTrace();
            }

        }
    }
}
